//
//  CBCar.m
//  CarsCube
//
//  Created by Wander See on 11-6-1.
//  Copyright 2011 Tongji Apple Club. All rights reserved.
//

#import "CBCar.h"
#import "GameEngine.h"

@implementation CBCar
@synthesize state = state_;

#pragma mark - Private Methods

- (void)playeEffectForState:(NSString *)state {
    NSString *theEffectName = [GameEngine effectForToolState:state];
    [audioEngine_ playEffect:theEffectName];
}

- (void)doAnimation {
    //[self.spriteBody removeAllChildrenWithCleanup:YES];
    [self stopAllActions];
    [self performSelector:[GameEngine selectorForToolState:self.state]];
    
    [self playeEffectForState:self.state];
}

#pragma mark - Normal Code

- (NSString *)description {
    return [NSString stringWithFormat:@"%p s:%@.", 
            self, 
            self.state];
}

- (id)init {
    self = [super init];
	if (self) {
        // Effects.
        audioEngine_ = [[SimpleAudioEngine alloc] init];
        
        self.state = kCarStateNormal;
	}
	return self;
}

- (void)onEnter {
    [super onEnter];
}

- (void)dealloc {
    [audioEngine_ release];
    [super dealloc];
}

#pragma mark - Public Methods

- (void)turn:(CBDirection)dir {
    
}

#pragma mark - States

- (void)doBYNormal {
    NSLog(@"CBCar normal.");
}

#pragma mark - Property

- (void)setState:(NSString *)st {
    state_ = st;
    [self doAnimation];
}

@end
